<template>
    <a-form :model="form" layout="inline" size="mini">
        <a-form-item label="客户">
            <a-input allow-clear class="bacClass" v-model="form.customName" :style="{ width: '150px' }"
                @press-enter="huiche" />
        </a-form-item>
        <a-form-item label="织布单号">
            <a-input allow-clear class="bacClass" v-model="form.planOrderCode" :style="{ width: '150px' }"
                @press-enter="huiche" />
        </a-form-item>
        <a-form-item label="坯布编号">
            <a-input allow-clear class="bacClass" v-model="form.greyCode" :style="{ width: '150px' }"
                @press-enter="huiche" />
        </a-form-item>
    </a-form>
    <a-spin :loading="loading" tip="加载中" dot style="height:100%;width: 100%;">
        <div class="cssToolbar">
            <Toolbar :items="['委外加工',
                `${permissionStore.hasPermisson('zbdpc.wpccx') ? '查询' : ''}`
                , `${permissionStore.hasPermisson('zbdpc.wpcdc') ? '导出' : ''}`,
                `${permissionStore.hasPermisson('zbdpc.pc') ? '排产' : ''}`, '排产(新)']" @select="cx" @del="delWeipaichan"
                @paic="paic" @export="exports" @oem="sendOemOrder" @paichanx="paichanxs"></Toolbar>
        </div>

        <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height:100%;width: 100%;z-index:999 ;">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                :suppressDragLeaveHidesColumns="true" rowSelection="multiple" @grid-ready="gridReady"
                @columnResized="onColumnResized" @columnMoved="onColumnMoved" @columnVisible="onColumnVisible"
                style="height:88%" :defaultColDef="defaultColDef" class='ag-theme-alpine' :rowData="table.dataList"
                :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
            <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size
                @change="PageSize" @page-size-change="change1" style="justify-content: center" :page-size="size"
                :current="page" />
        </a-spin>
    </a-spin>
    <!-- sideNo1 -->
    <a-drawer style="z-index:999" :drawer-style="{ 'zIndex': 999 }" ok-text="保存" cancel-text="关闭" :height="'100%'"
        :visible="pageData.showAdd" placement="bottom" unmountOnClose @ok="sidesOks" @cancel="sideNo1" :closable="false">
        <template #title>
            {{ isYupai }}
        </template>
        <div class="iscon">
            <div class="iscontent">
                <a-form ref="formRef" :model="dataListss" size="mini" layout="vertical" :width="'800px'">
                    <div>
                        <a-space>
                            <a-form-item label="排产号" field="schedulCode">
                                <!-- 标记 -->
                                <a-input disabled placeholder="" v-model="dataListss.schedulCode"
                                    :style="{ width: '300px' }" />
                            </a-form-item>

                            <a-form-item label="适用机型" field="applyMachine">

                                <a-input disabled class="bacClass" v-model="dataListss.applyMachine"
                                    :style="{ width: '300px' }" />
                            </a-form-item>
                            <a-form-item label="指定楼层" field="storey">
                                <a-select popup-container="html"  class="bacClass" v-model="queryData.storey" :style="{ width: '300px' }"
                                    @change="storeyStors" allow-clear>
                                    <a-option v-for="item in pageData.clothListr" :value="item">{{
                                        item
                                    }}</a-option>
                                </a-select>

                            </a-form-item>
                            <a-form-item label="机台数">

                                <a-input disabled v-model="macNum" :style="{ width: '300px' }" />
                            </a-form-item>
                        </a-space>
                    </div>
                </a-form>

                <AgGridVuesCopys :suppressCopyRowsToClipboard="true" rowSelection="multiple" style="height:12%" :rowHeight="30"
                    :headerHeight="30" :defaultColDef="defaultColDef" class='ag-theme-alpine' :rowData="dataListssz"
                    :columnDefs="tc5" :localeText="localeText1" @grid-ready="gridReady5" @click="clickRowSelectionA">
                </AgGridVuesCopys>
                <a-checkbox-group style="" :default-value="machinesIdArray" @change="macChanges">
                    <div class="bg-content">
                        <!-- @change="changeId" -->
                        <span class="bg-contentA" style="display:flex;">
                            <a-tag id="aTag" color="#5e8af5">推荐机台
                            </a-tag>
                            <div v-for="(item, index) in machineIDs2">
                                <div :class="item.state == 0 ? 'lvClass' : item.state == 1 ? 'huClass' : 'wxClass'">
                                    <a-checkbox v-model="item.id" :value="item.id">
                                        <span>
                                            <a-popover title="详情">
                                                <a-button type="primary" shape="round" size="mini">{{ item.machineCode
                                                }}-机台明细</a-button>
                                                <template #content>
                                                    <p>机台类型：{{ item.machineTypeName }}</p>
                                                    <p>区域：{{ item.areaName }}</p>
                                                    <p>织布单号个数：{{ item.incompleteNum }}</p>
                                                    <p>织布单号总量：{{ item.incompleteWeight }}</p>
                                                </template>
                                            </a-popover>
                                        </span>
                                    </a-checkbox>
                                </div>
                            </div>
                        </span>
                        <!-- <span class="bg-contentA" v-for="(items, Key, index) in machineSObj">
                            <a-tag id="aTag" color="#5e8af5" v-if="showMachineList.includes(Key)">{{ Key }}</a-tag>
                            <div v-for="(item, index) in items">
                                <div :class="item.state == 0 ? 'lvClass' : item.state == 1 ? 'huClass' : 'wxClass'"
                                    v-if="showMachineList.includes(Key)">
                                    
                                    <a-checkbox v-model="item.id" :value="item.id">
                                        <span>
                                            <a-popover title="机台明细">
                                                <a-button type="primary" shape="round" size="mini">{{ item.machineCode
                                                }}-机台明细</a-button>
                                                <template #content>
                                                    <p>机台类型：{{ item.machineTypeName }}</p>
                                                    <p>区域：{{ item.areaName }}</p>
                                                    <p>织布单号个数：{{ item.incompleteNum }}</p>
                                                    <p>织布单号总量：{{ item.incompleteWeight }}</p>
                                                </template>
                                            </a-popover>
                                        </span>
                                    </a-checkbox>
                                </div>
                            </div>
                        </span> -->
                    </div>
                    <a-tabs   :lazy-load="true" :active-key="tabKey" @change="tabchange" style="width:100%;height:80%;">
                        <template #extra>
                            <a-space style="margin-left: 10px;">
                                <div style="width: 30px;height: 30px;background-color: rgb(99,222,235);"></div>
                                <span>空闲</span>
                                <div style="width: 30px;height: 30px;background-color: #5959f5;"></div><span>调机</span>
                                <div style="width: 30px;height: 30px;background-color: #4cc784"></div><span>生产</span>
                                <div style="width: 30px;height: 30px;background-color: rgb(239,118,118)"></div>
                                <span>维修</span>
                                <a-button type="primary" @click="selectClickAll">查看所有机台</a-button>
                            </a-space>
                        </template>
                        <a-tab-pane style="overflow: auto;height:100%;" :key="index" :title="z.story"
                            v-for="(z, index) in ArrayList">
                            <div class="layoutBox">
                                <grid-layout :layout.sync="z.detail.layout" :col-num="z.detail.form.long"
                                    :row-height="z.detail.form.heigt" :responsive="false" :vertical-compact="false"
                                    :prevent-collision="false" :use-css-transforms="false" :is-draggable="false"
                                    :is-resizable="false" class="grid_cals2">
                                    <div>
                                        <grid-item style="zoom:1" v-for="item in z.detail.backgroundData" :x="item.x"
                                            :y="item.y" :w="item.w" :h="item.h" :i="item.i" :key="item.i"
                                            :is-draggable="false" :is-resizable="false" class="grid-item" />
                                    </div>
                                    <grid-item :key="item.i" v-for="item in z.detail.layout" :x="item.x" :y="item.y"
                                        :w="item.w" :h="item.h" :i="item.i"
                                        :style="{ background: getColor(item.text, item.type), zoom: 1 }"
                                        :class="{ borderClass: item.isBooval }">
                                        <div class="clmodule" @dblclick="getEdit(item)">
                                            <div v-if="item.text == '机台'">
                                                <a-popover title="详情" style="text-align: center;">
                                                    <a-button type="text"
                                                        :style="{ color: '#000', fontSize: '12px', width: '40px' }"
                                                        size="mini">{{ item.materialName }}</a-button>
                                                    <template #content>
                                                        <p>物料大类：{{ item.majorCategory }}</p>
                                                        <p>物料中类：{{ item.middleCategory }}</p>
                                                        <p>物料小类：{{ item.subCategory }}</p>
                                                        <p>物料编号：{{ item.materialCode }}</p>
                                                        <p>物料名称：{{ item.materialName }}</p>
                                                        <p>规格：{{ item.specification }}</p>
                                                        <p>机台编号：{{ item.numberId }}</p>
                                                        <p>是否勾选：<a-checkbox v-model="item.id" :value="item.id"></a-checkbox>
                                                        </p>
                                                    </template>
                                                </a-popover>
                                            </div>
                                            <div v-if="item.text == '机台'"
                                                :style="{ wordBreak: 'break-all', width: '100%', textAlign: 'center', overflow: 'hidden', fontWeight: '600' }">
                                                {{
                                                    item.numberId }}
                                            </div>
                                            <div v-if="item.text != '机台'" style="width:100%;text-align:center;">{{
                                                item.text }}
                                            </div>
                                        </div>
                                    </grid-item>
                                </grid-layout>
                            </div>
                        </a-tab-pane>
                        <a-tab-pane key="888" title="机台明细">
                            <el-table class="elTable" :data="ArrayListMacAll" border style="width: 100%;height:400px">
                                <el-table-column prop="" label="" width="50">
                                    <template #default="scope">
                                        <a-checkbox v-model="scope.row.id" :value="scope.row.id"></a-checkbox>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="numberId" label="机台号" width="180" />
                                <el-table-column prop="machineTypeName" label="机型" width="180" />
                                <el-table-column prop="area" label="位置号" width="180" />
                                <el-table-column prop="type" label="机台状态" width="180">
                                    <template #default="scope">
                                        {{ scope.row.type == 0 ? '空闲' : scope.row.type == 1 ? '调机' : scope.row.type == 2 ?
                                            '生产' : scope.row.type == 3 ? '维修' : '' }}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="greyCode" label="坯布编号" width="180" />
                                <el-table-column prop="greyName" label="坯布名称" width="180" />
                                <el-table-column prop="workDrum" label="针筒" width="180" />
                                <el-table-column prop="yarnLong" label="纱长" width="180" />
                                <el-table-column prop="finishTime" label="完成时间" width="180" />
                            </el-table>
                        </a-tab-pane>
                    </a-tabs>
                </a-checkbox-group>
            </div>
            <div class="iscontent2">
                <div class="iscontent21">
                    <div class="divs">
                        <a-tag color="#5e8af5">机台动态</a-tag>
                        <AgGridVuesCopys :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady2"
                            style="height:90%" :rowHeight="30" :headerHeight="30" :defaultColDef="defaultColDef"
                            class='ag-theme-alpine' :rowData="jtdtBiao" :columnDefs="tc2" @click="clickRowSelection"
                            :localeText="localeText1"></AgGridVuesCopys>
                    </div>
                    <div class="divs">
                        <a-tag color="#5e8af5">机台任务明细</a-tag>
                        <AgGridVuesCopys :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady3"
                            style="height:90%" :rowHeight="30" :headerHeight="30" :defaultColDef="defaultColDef"
                            class='ag-theme-alpine' :rowData="jtewmxBiao" :columnDefs="tc3" :localeText="localeText1">
                        </AgGridVuesCopys>
                    </div>
                    <div class="divs">
                        <a-tag color="#5e8af5">试算明细</a-tag>
                        <AgGridVuesCopys :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady4"
                            style="height:90%" :rowHeight="30" :headerHeight="30" :defaultColDef="defaultColDef"
                            class='ag-theme-alpine' :rowData="ssmxBiao" :columnDefs="tc4" :localeText="localeText1">
                        </AgGridVuesCopys>
                    </div>
                    <div class="divs2">
                        <span>
                            <a-button type="primary" @click="shiSuans">试算</a-button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </a-drawer>
    <a-modal :width="1200" v-model:visible="visible" :on-before-ok="handleOk" @cancel="handleCancel">
        <template #title>
            机台排产详情
        </template>
        <div class="jitaipaic">
            <div><span>最大可排产天数{{ maxData }}</span></div>
            <div class="jitaipaic1"><span>计划重量{{ orderWeight }}KG</span></div>
        </div>
        <a-table :scrollbar="true" sticky-header size="mini" :columns="columns" :data="data" :pagination="false"
            :style="{ height: '500px' }">
            <template v-for="(item, index) in columns" #[item.slotName]="{ record }">
                <div>
                    <a-input-number class="bacClass" allow-clear v-model="record[item.slotName]">
                        <template #append>
                            KG
                        </template>
                    </a-input-number>
                </div>
            </template>
        </a-table>
    </a-modal>


    <a-drawer style="z-index:999" :drawer-style="{ 'zIndex': 999 }" ok-text="关闭" :height="'100%'" :visible="GTpc"
        placement="bottom" unmountOnClose @ok="GTpc = false" :closable="false" :hideCancel="true">
        <template #title>
            甘特图排产
        </template>
        <GanttChartChart></GanttChartChart>
    </a-drawer>


    <a-modal ok-text="关闭" v-model:visible="visibleSelectAll" @ok="visibleSelectAll = false" fullscreen :hide-cancel="true"
        :closable="false">
        <template #title>
            <div style="width:80%">所有楼层</div>
            <a-space style="margin-left: 10px;">
                <div style="width: 30px;height: 30px;background-color: rgb(99,222,235);"></div>
                <span>空闲</span>
                <div style="width: 30px;height: 30px;background-color: #5959f5;"></div><span>调机</span>
                <div style="width: 30px;height: 30px;background-color: #4cc784"></div><span>生产</span>
                <div style="width: 30px;height: 30px;background-color: rgb(239,118,118)"></div>
                <span>维修</span>
            </a-space>
        </template>
        <a-card :style="{ width: '100%', height: '82%', marginBottom: '10px' }" :title="z.story"
            v-for="(z, index) in ArrayList" hoverable>
            <div class="layoutBoxs">
                <grid-layout :layout.sync="z.detail.layout" :col-num="z.detail.form.long" :row-height="z.detail.form.heigt"
                    :responsive="false" :vertical-compact="false" :prevent-collision="false" :use-css-transforms="false"
                    :is-draggable="false" :is-resizable="false" class="grid_cals2">
                    <div>
                        <grid-item style="zoom:1" v-for="item in z.detail.backgroundData" :x="item.x" :y="item.y"
                            :w="item.w" :h="item.h" :i="item.i" :key="item.i" :is-draggable="false" :is-resizable="false"
                            class="grid-item" />
                    </div>
                    <grid-item :key="item.i" v-for="item in z.detail.layout" :x="item.x" :y="item.y" :w="item.w" :h="item.h"
                        :i="item.i" :style="{ background: getColor(item.text, item.type), zoom: 1 }"
                        :class="{ borderClass: item.isBooval }">
                        <div class="clmodule" @dblclick="getEdit(item)">
                            <div v-if="item.text == '机台'" style="width:100%;text-align:center;">
                                <a-popover title="详情">
                                    <a-button type="text" :style="{ color: '#000', fontSize: '12px' }" size="mini">{{
                                        item.materialName }}</a-button>
                                    <template #content>
                                        <p>物料大类：{{ item.majorCategory }}</p>
                                        <p>物料中类：{{ item.middleCategory }}</p>
                                        <p>物料小类：{{ item.subCategory }}</p>
                                        <p>物料编号：{{ item.materialCode }}</p>
                                        <p>物料名称：{{ item.materialName }}</p>
                                        <p>规格：{{ item.specification }}</p>
                                        <p>机台编号：{{ item.numberId }}</p>
                                    </template>
                                </a-popover>
                            </div>
                            <div v-if="item.text == '机台'"
                                :style="{ wordBreak: 'break-all', width: '100%', textAlign: 'center', fontWeight: '600' }">{{
                                    item.numberId }}
                            </div>
                            <div v-if="item.text != '机台'" style="width:100%;text-align:center;">{{
                                item.text }}
                            </div>
                        </div>
                    </grid-item>
                </grid-layout>
            </div>
        </a-card>
    </a-modal>
</template>
 
<script lang='ts' setup>
import { reactive, toRefs, ref, onMounted, watch } from 'vue'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'
import Toolbar from '@/components/Toolbar.vue'
import { post } from '@/api/http'
import { Message } from '@arco-design/web-vue'
import { Modal } from '@arco-design/web-vue'
import { ValueData } from '@arco-design/web-vue/es/_utils/types'

import dayjs from 'dayjs';
import { localeText } from '@/api/aggridZw'
import { useRoute, useRouter } from 'vue-router'
import emitter from '@/hooks/useEventBus'
import usePermission from '@/store/modules/permission'
import EmbroideryList from '@/components/product/ProductManagement/EmbroideryList.vue'
import { pagingList } from '@/api/paging'
import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
import GanttChartChart from "@/views/YarnStrippings/GanttChartChart.vue";
const permissionStore = usePermission()
const pagingList1: any = ref(pagingList)
const router = useRouter()

const gridOption = ref()
const colState = ref()
const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
}

const gridOption2 = ref()
const gridReady2 = (params: any) => {
    gridOption2.value = params.api
}

const gridOption3 = ref()
const gridReady3 = (params: any) => {
    gridOption3.value = params.api
}

const gridOption4 = ref()
const gridReady4 = (params: any) => {
    gridOption4.value = params.api
}

const gridOption5 = ref()
const gridReady5 = (params: any) => {
    gridOption5.value = params.api
}

const { selectedRowKeys } = useRowSelection()
const selectedKeys2: any = ref()
const clickRowSelection = () => {
    selectedKeys2.value = gridOption2.value.getSelectedRows().map((res: any) => res.id)
}
const objArray: any = ref([])
watch(() => selectedKeys2.value, (newData, oldData) => {
    objArray.value = []
    jtdtBiao.value.forEach((o: any) => {
        if (selectedKeys2.value.includes(o.id)) {
            objArray.value.push(o)
        }
    })
    post({
        url: 'planSingle/planSchedul/getScheduleInfoByMachineAll',
        data: objArray.value
    }).then((res: any) => {
        if (res.code == 200) {
            jtewmxBiao.value = res.data
            // if(res.data.length == 0){
            //     Message.warning('无任务明细')
            // }else if(objArray.length == 0){
            //     Message.warning('请勾选机台动态表')
            // }
        } else {
            Message.error(res.message)
        }
    })

})

const ssmxBiao2: any = ref([])

const shiSuans = () => {
    // if (selectedKeys2.value.length == 0) {
    //     ssmxBiao.value = []
    //     Message.warning('请先勾选机台动态表')
    // } else {
    //     post({
    //         url: 'planSingle/planSchedul/getScheduleCalculate',
    //         data: {
    //             ...dataListssz.value[0],
    //             weavDeliveryDate: dataListssz.value[0].lastDeliveryTime,
    //             ...dataListss,
    //             storey: queryData.storey,
    //             // machine: objArray.value
    //             machine: machineIDs.value
    //         }
    //     }).then((res: any) => {
    //         if (res.code == 200) {
    //             ssmxBiao.value = res.data
    //         } else {
    //             Message.error(res.message)
    //         }
    //     })
    // }
    let ssmxBiao3: any = []
    for (let i = 0; i < ssmxBiao.value.length; i++) {
        if (ssmxBiao.value[i].alreadyWeight != ssmxBiao2.value[i].alreadyWeight) {
            ssmxBiao3.push(ssmxBiao.value[i])
        }
    }
    post({
        url: 'planSingle/planSchedul/getScheduleCalculate',
        data: {
            ...dataListssz.value[0],
            weavDeliveryDate: dataListssz.value[0].lastDeliveryTime,
            ...dataListss,
            storey: queryData.storey,
            // machine: objArray.value
            machine: machineIDs.value,
            taskDetail: jtewmxBiao.value,
            calculateData: ssmxBiao3
        }
    }).then((res: any) => {
        if (res.code == 200) {
            ssmxBiao.value = res.data
            setTimeout(() => {
                gridOption4.value.setRowData(res.data)
            }, 0)
            ssmxBiao2.value = JSON.parse(JSON.stringify(res.data))
        } else {
            Message.error(res.message)
        }
    })
}


onMounted(() => {
    pageData.rHeight = document.getElementsByClassName("main-section")[0]?.clientHeight
    //弹出层的高
    if (pageData.rHeight !== undefined) {
        pageData.rHeight = pageData.rHeight;
    }
    doRefresh()
    post({
        url: 'planSingle/planSchedul/upRedis'
    })
})

// let rangeValue = ref()
const total = ref(10);
const page = ref(1);
const size = ref(10);
function PageSize(val: any) {
    page.value = val
    doRefresh();
}
function change1(val: any) {
    size.value = val
    doRefresh();
}

function doRefresh() {
    pageData.pageLoading = true
    updateGridState01()
    post({
        url: "planSingle/planSchedul/getPageInfo",
        data: {
            page: page.value,
            size: size.value,
            deleteState: 0,
            schedulState: 0,
            customName: form.customName,
            planOrderCode: form.planOrderCode,
            greyCode: form.greyCode
        },
    })
        .then(({ data, code }: any) => {
            if (code === 200) {
                lc();
                gridOption.value.setRowData(data.list)
                table.handleSuccess(data.list);
                emitter.emit('bcCx')
                total.value = data.total;
            }
        })
        .catch(console.log).finally(() => {
            pageData.pageLoading = false
        });
}

const checkboxs = () => {
    Message.error('请先选择时间')
}

const cx = () => {
    page.value = 1
    doRefresh()
}
const handleSelect = (key: any) => {
    let ids = 0
    switch (key) {
        case '紧急':
            ids = 2
            break;
        case '急':
            ids = 1
            break;
        case '正常':
            ids = 0
            break;
        default:
            break;
    }
    post({
        url: "planSingle/planSchedul/update",
        data: [{
            id: Number(selectIsh.id),
            planOrderState: Number(ids)
        }],
    }).then((res: any) => {
        if (res.code === 200) {
            doRefresh()
            console.log('666' + table.dataList)
            Message.success('修改成功')
        } else {
            Message.error(res.message)
        }
    })
}
let selectIsh: {
    id: any
} = {
    id: ''
}
//btn获取当前行信息
const handleSelects = (key: any) => {
    selectIsh = key
}
const pagination = usePagination(doRefresh)
const rowKey = useRowKey("id")
const queryData = reactive({
    firm: "",
    clothType: "",
    storey: ''
})
const delWeipaichan = () => {
    let isArray: any[] = []
    gridOption.value.getSelectedRows().forEach((item: any) => {
        isArray.push(item.id)
    })
    if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
    }
    Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
            // console.log(selectedRowKeys.value.values)
            post({
                url: 'planSingle/planSchedul/delete',
                data: isArray
            }).then(({ code, data }: any) => {
                if (code === 200) {
                    doRefresh()
                    selectedRowKeys.value = []
                    Message.success({
                        content: '删除成功',
                        duration: 5000
                    })
                } else {
                    Message.success({
                        content: '删除失败',
                        duration: 5000
                    })
                }
            })
        }
    })
}

const machinesIdArray: any = ref([])
const machineIDs: any = ref([])
const machineIDs2: any = ref([])
const machineIDs3: any = ref([])
const machineS: any = ref([])
const machineS2: any = ref([])

const machineSObj: any = ref()

const jtdtBiao: any = ref([])
const jtewmxBiao: any = ref([])
const ssmxBiao: any = ref([])

const macChanges = (e: any) => {
    console.log(e)
    let objArrays: any = []
    machinesIdArray.value = e
    machineS2.value.forEach((v: any) => {
        if (e.includes(v.id)) {
            objArrays.push(v)
        }
    })
    machineIDs.value = JSON.parse(JSON.stringify(objArrays))
    post({
        url: 'planSingle/planSchedul/getScheduleInfoByMachine',
        data: machineIDs.value
    }).then((res: any) => {
        if (res.code == 200) {
            jtdtBiao.value = res.data
        } else {
            Message.error(res.message)
        }
    })
}
const showMachineList = ref([]);
const storeyStors = (val: any) => {
    if (val == '') {
        //当楼层框不选择时 默认显示所有数据
        showMachineList.value.push(...pageData.clothListr)
        let objMachineS: any = []
        machineS2.value.forEach((o: any) => {
            if (!machinesIdArray.value.includes(o.id)) {
                objMachineS.push(o)
            }
        })
        machineS.value = JSON.parse(JSON.stringify(objMachineS))
        machineS.value.unshift(...machineIDs.value)
    } else {
        //先清空上一次选择的楼层数据
        showMachineList.value = []
        showMachineList.value.push(val)
        let objMachineS: any = []
        machineS2.value.forEach((res: any) => {
            if (!machinesIdArray.value.includes(res.id)) {
                if (res.areaName == val) {
                    objMachineS.push(res)
                }
            }
        })
        machineS.value = JSON.parse(JSON.stringify(objMachineS))
        machineS.value.unshift(...machineIDs.value)
    }
}

const ArrayJTDT: any = ref([])
const ArrayJTRWMX: any = ref([])
const ArrayJTSS: any = ref([])

const loading: any = ref(false)

const paic = async () => {
    machinesIdArray.value = []
    machineIDs.value = []
    machineS.value = []
    machineS2.value = []
    changeIds.value = []
    changeIdArry = []
    selectedRowKeys.value = []
    jtdtBiao.value = []
    jtewmxBiao.value = []
    ssmxBiao.value = []
    selectedKeys2.value = []
    objArray.value = []
    if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选');
        return
    }
    if (gridOption.value.getSelectedRows().length > 1) {
        Message.error('只能勾选一条')
        return
    }
    // Modal.success({
    //     title: '系统提示',
    //     content: '订单审核通过已到已排产界面',
    //     onOk() {
    //         post({
    //             url: "planSingle/planSchedul/update",
    //             data: [{
    //                 id: Number(selectedRowKeys.value),
    //                 schedulState: Number(2)
    //             }],
    //         }).then((res: any) => {
    //             if (res.code === 200) {
    //                 doRefresh()
    //                 Message.success('修改成功')
    //             } else {
    //                 Message.error(res.message)
    //             }
    //         })
    //     }
    // })
    selectClickArrayList()
    selectMxAll()
    loading.value = true
    showMachineList.value = pageData.clothListr
    let firm = ''
    let planOrderId = ''
    let planOrderCode = ''
    let items: any;
    table.dataList.forEach(item => {
        if (item.id == gridOption.value.getSelectedRows().map((o: any) => { return o.id })[0]) {
            items = item
            firm = item.firm
            planOrderId = item.planOrderId
            planOrderCode = item.planOrderCode
            dataListss.schedulCode = item.schedulCode
            dataListss.computerTime = item.computerTime
            dataListss.applyMachine = item.applyMachine
            dataListss.firm = item.firm
            queryData.storey = item.storey
            dataListss.defaultNum = item.defaultNum
            dataListss.planOrderId = item.planOrderId
            dataListss.planOrderCode = item.planOrderCode
        }
    })
    const res: any = await post({
        url: 'planSingle/planSchedul/redisOut',
        data: [planOrderCode]
    })
    if (res.code == 200) {
        post({
            url: "planSingle/planSchedulDetail/getList",
            data: {
                id: Number(gridOption.value.getSelectedRows().map((o: any) => { return o.id })),
                firm,
                planOrderId,
                planOrderCode,
                applyMachine: dataListss.applyMachine,
                storey: queryData.storey,
            },
        }).then((resq: any) => {
            if (resq.code == 200) {
                macNum.value = resq.data.machineNum
                dataListssz.value = [resq.data.planSchedulDetails[0]]
                dataListssz.value[0]['planOrderCode'] = planOrderCode
                dataListssz.value[0]['greyId'] = resq.data.greyId
                dataListsss.value = resq.data.planSchedulLooms
                post({
                    url: 'planSingle/planSchedul/getAutomaticInfo'
                }).then((resw: any) => {
                    if (resw.code == 200) {

                        dataListss.schedulCode = resw.data.schedulCode

                    }
                })

                post({
                    url: '/planSingle/planSchedul/getAutoScheduleInfo',
                    data: items
                }).then((rese: any) => {
                    if (rese.code == 200) {
                        // machineSObj
                        // ArrayListMacAll.value = rese.data.machineData
                        // console.log(ArrayListMacAll.value)
                        let jitai: any;
                        machineS.value = JSON.parse(JSON.stringify(rese.data.machineData))
                        machineS2.value = JSON.parse(JSON.stringify(rese.data.machineData))
                        machineIDs2.value = []
                        machineIDs3.value = []
                        machineIDs.value = []
                        machinesIdArray.value = []
                        // for (let i = 0; i < rese.data.machineNum; i++) {
                        //     // if (i < Math.ceil(rese.data.machineNum / 2)) {
                        //         machineIDs2.value.push(JSON.parse(JSON.stringify(rese.data.machineData[i])))
                        //     // } else {
                        //     //     machineIDs3.value.push(JSON.parse(JSON.stringify(rese.data.machineData[i])))
                        //     // }
                        //     machineIDs.value.push(rese.data.machineData[i])
                        //     machinesIdArray.value.push(rese.data.machineData[i].id)
                        // }
                        for (let i = 0; i < rese.data.machineNum; i++) {
                            machineIDs.value.push(rese.data.machineData[i])
                            machineIDs2.value.push(JSON.parse(JSON.stringify(rese.data.machineData[i])))
                            machinesIdArray.value.push(rese.data.machineData[i].id)
                        }
                        jitai = machineS.value.slice(rese.data.machineNum)
                        machineSObj.value = {

                        }
                        jitai.forEach((o: any) => {
                            if (!Object.keys(machineSObj.value).includes(o.areaName)) {
                                machineSObj.value[o.areaName] = []
                                machineSObj.value[o.areaName].push(o)
                            } else {
                                machineSObj.value[o.areaName].push(o)
                            }
                        })
                        // JSON.parse(JSON.stringify(Object.keys(machineSObj.value))).forEach((res: any, index: any) => {
                        //     machineSObj.value[res][0] = machineSObj.value[res].filter((res2:any,index2:any)=>{
                        //           return index2 < Math.ceil(machineSObj.value[res].length / 2)
                        //     })
                        //     machineSObj.value[res][1] = machineSObj.value[res].filter((res2:any,index2:any)=>{
                        //           return index2 >= Math.ceil(machineSObj.value[res].length / 2)
                        //     })

                        // })
                        // console.log(machineSObj.value)
                        post({
                            url: '/planSingle/planSchedul/getScheduleInfoByMachine',
                            data: machineIDs.value
                        }).then((resz: any) => {
                            if (resz.code == 200) {
                                jtdtBiao.value = resz.data
                                // post({
                                //     url: 'planSingle/planSchedul/getScheduleInfoByMachineAll',
                                //     data: jtdtBiao.value
                                // }).then((yyy: any) => {
                                //     if (yyy.code == 200) {
                                //         jtewmxBiao.value = yyy.data
                                post({
                                    url: 'planSingle/planSchedul/getScheduleCalculate',
                                    data: {
                                        ...dataListssz.value[0],
                                        weavDeliveryDate: dataListssz.value[0].lastDeliveryTime,
                                        ...dataListss,
                                        storey: queryData.storey,
                                        // machine: objArray.value
                                        machine: machineIDs.value,
                                        taskDetail: jtewmxBiao.value,
                                        calculateData: ssmxBiao.value
                                    }
                                }).then((resb: any) => {
                                    if (resb.code == 200) {
                                        ssmxBiao.value = resb.data
                                        ssmxBiao2.value = JSON.parse(JSON.stringify(resb.data))
                                        loading.value = false
                                        pageData.showAdd = true
                                        isYupai.value = '排产'
                                        isS = setInterval(() => {
                                            post({
                                                url: 'planSingle/planSchedul/redisOut',
                                                data: [planOrderCode]
                                            })
                                        }, 50000)
                                    } else {
                                        loading.value = false
                                        clearInterval(isS)
                                        post({
                                            url: 'planSingle/planSchedul/upRedis'
                                        })
                                        Message.error(resb.message)
                                    }
                                })
                                //     } else {
                                //         loading.value = false
                                //         Message.error(yyy.message)
                                //     }
                                // })
                            } else {
                                clearInterval(isS)
                                post({
                                    url: 'planSingle/planSchedul/upRedis'
                                })
                                loading.value = false
                                Message.error(resz.message)
                            }
                        })
                        // pageData.showAdd = true
                        // isYupai.value = '排产'
                    } else {
                        clearInterval(isS)
                        post({
                            url: 'planSingle/planSchedul/upRedis'
                        })
                        loading.value = false
                        Message.error(rese.message)
                    }
                })
                // } else {
                //     Message.error('还未预排')
                // }
            } else {
                clearInterval(isS)
                post({
                    url: 'planSingle/planSchedul/upRedis'
                })
                loading.value = false
                Message.error(resq.message)
            }
        })
    } else {

        clearInterval(isS)
        post({
            url: 'planSingle/planSchedul/upRedis'
        })
        loading.value = false
        Message.error(res.message)
    }
    // isDeFou(firm, planOrderId, Number(selectedRowKeys.value), planOrderCode, dataListss.applyMachine, dataListss.storey)

}

const exports = () => {
    if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
    } else {
        //将表头拼接出来
        let head = "<th>织布单号</th><th>客户</th><th>坯布编号</th><th>坯布名称</th><th>面料种类</th><th>下单重量</th><th>计划状态</th><th>下单时间</th><th>计划单状态</th>"
        //拿到当前表格数据与勾选的行做筛选

        let nowRow = table.dataList.filter(function (o) {
            return (gridOption.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
        })
        let body = "";
        nowRow.forEach(function (o) {
            body += "<tr><td>" + o["planOrderCode"] + "</td>";
            body += "<td>" + o["customName"] + "</td>";
            body += "<td>" + o["greyCode"] + "</td>";
            body += "<td>" + o["greyName"] + "</td>";
            body += "<td>" + o["fabricType"] + "</td>";
            body += "<td>" + o["orderWeight"] + "</td>";
            body += "<td>" + (o["planState"] == 0 ? "自行生产" : "") + "</td>";
            body += "<td>" + o["examineTime"] + "</td>";
            body += "<td>" + (o["planOrderState"] == 0 ? "正常" : (o["planOrderState"] == 1 ? "急" : "紧急")) + "</td>";
            body += "</tr>";
        })
        tableToXlsx(head, '计划单排产-未排产', body)
    }
}

function tableToXlsx(head: any, filename: any, body: any) {
    const uri = 'data:application/vnd.ms-excel;base64,',
        template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`;

    const a = document.createElement('a');
    a.href = uri + window.btoa(unescape(encodeURIComponent(template)));
    a.download = filename;
    a.click();
    document.removeChild(a);
}

const tableColumns = useTableColumn([
    // {
    //     title: "排产号",
    //     key: "schedulCode",
    //     dataIndex: "schedulCode",
    //     width: 150,
    // },
    {
        title: "公司",
        key: "outSouringCompany",
        dataIndex: "outSouringCompany",
        width: 150,
    },
    {
        title: "织布单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    // {
    //     title: "计划类型",
    //     key: "planType",
    //     dataIndex: "planType",
    //     width: 150,
    // },
    {
        title: "客户",
        key: "customName",
        dataIndex: "customName",
        width: 150,
    },
    // {
    //     title: "机台号",
    //     key: "schedulMachineCode",
    //     dataIndex: "schedulMachineCode",
    //     width: 150,
    // },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 200,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    // {
    //     title: "产品类别",
    //     key: "productType",
    //     dataIndex: "productType",
    //     width: 150,
    // },
    {
        title: "面料种类",
        key: "fabricType",
        dataIndex: "fabricType",
        width: 150,
    },
    // {
    //     title: "品牌",
    //     key: "brandName",
    //     dataIndex: "brandName",
    //     width: 150,
    //     align: 'left'
    // },
    {
        title: "下单重量",
        key: "orderWeight",
        dataIndex: "orderWeight",
        width: 150,
    },
    // {
    //     title: "加工单价",
    //     key: "machinPrice",
    //     dataIndex: "machinPrice",
    //     width: 150,
    // },
    // {
    //     title: "加工金额",
    //     key: "machinMoney",
    //     dataIndex: "machinMoney",
    //     width: 150,
    // },
    {
        title: "计划单状态",
        key: "planOrderState",
        dataIndex: "planOrderState",
        slotName: 'planOrderState',
        width: 150,
        fixed: 'right'
    },
    // {
    //     title: "订单交期",
    //     key: "orderDeliveryDate",
    //     dataIndex: "orderDeliveryDate",
    //     width: 150,
    // },
    {
        title: "计划状态",
        key: "planState",
        dataIndex: "planState",
        slotName: 'planState',
        width: 150,
    },
    {
        title: "下单时间",
        key: "examineTime",
        dataIndex: "examineTime",
        slotName: 'examineTime',
        width: 150,
    },
])

const tableColumns1: any = useTableColumn([
    {
        title: "织布单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 150,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    // {
    //     title: "产品类别",
    //     key: "productType",
    //     dataIndex: "productType",
    //     width: 150,
    // },
    {
        title: "计划总量",
        key: "planCount",
        dataIndex: "planCount",
        width: 150,
    },
    {
        title: "已排量",
        key: "alreadySchedulingNum",
        dataIndex: "alreadySchedulingNum",
        width: 150,
    },
    {
        title: "本次排程量",
        key: "onceSchedulingNum",
        dataIndex: "onceSchedulingNum",
        width: 150,
    },
    {
        title: "适用机型",
        key: "applyMachine",
        dataIndex: "applyMachine",
        width: 150,
    },
    {
        title: "最晚交期",
        key: "lastDeliveryTime",
        dataIndex: "lastDeliveryTime",
        width: 150,
    },
])

const tableColumns2: any = [
    {
        title: "织造单号",
        key: "weaveingCode",
        dataIndex: "weaveingCode",
        width: 150,
    },
    {
        title: "机台号",
        key: "machineCode",
        dataIndex: "machineCode",
        width: 150,
    },
    {
        title: "位置号",
        key: "storey",
        dataIndex: "storey",
        width: 150,
    },
    {
        title: "计划单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 200,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    {
        title: "产品类别",
        key: "productType",
        dataIndex: "productType",
        width: 150,
    },
    {
        title: "已排重量",
        key: "alreadyWeight",
        dataIndex: "alreadyWeight",
        width: 150,
    },
    {
        title: "匹数",
        key: "pieceNum",
        dataIndex: "pieceNum",
        width: 150,
    },
    {
        title: "上线时间",
        key: "startTime",
        dataIndex: "startTime",
        width: 180,
    },
    {
        title: "完成时间",
        key: "endTime",
        dataIndex: "endTime",
        width: 180,
    },
    {
        title: "针筒",
        key: "workDrum",
        dataIndex: "workDrum",
        width: 150,
    },
    {
        title: "订单交期",
        key: "weavDeliveryDate",
        dataIndex: "weavDeliveryDate",
        width: 150,
    },
    {
        title: "机台状态",
        key: "pStart",
        dataIndex: "pStart",
        slotName: 'pStart',
        width: 100,
        fixed: 'right'
    },
]
const tableColumns4: any = [
    {
        title: "生产序号",
        key: "serialNum",
        dataIndex: "serialNum",
        width: 150,
    },
    {
        title: "织造单号",
        key: "weaveingCode",
        dataIndex: "weaveingCode",
        width: 150,
    },
    {
        title: "机台号",
        key: "machineCode",
        dataIndex: "machineCode",
        width: 150,
    },
    {
        title: "位置号",
        key: "storey",
        dataIndex: "storey",
        width: 150,
    },
    {
        title: "计划单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 200,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    {
        title: "产品类别",
        key: "productType",
        dataIndex: "productType",
        width: 150,
    },
    {
        title: "已排重量",
        key: "alreadyWeight",
        dataIndex: "alreadyWeight",
        width: 150,
    },
    {
        title: "匹数",
        key: "pieceNum",
        dataIndex: "pieceNum",
        width: 150,
    },
    {
        title: "上线时间",
        key: "startTime",
        dataIndex: "startTime",
        width: 180,
    },
    {
        title: "完成时间",
        key: "endTime",
        dataIndex: "endTime",
        width: 180,
    },
    {
        title: "针筒",
        key: "workDrum",
        dataIndex: "workDrum",
        width: 150,
    },
    {
        title: "订单交期",
        key: "weavDeliveryDate",
        dataIndex: "weavDeliveryDate",
        width: 150,
    },
    {
        title: "生产状态",
        key: "pStart",
        dataIndex: "pStart",
        slotName: 'pStart',
        width: 100,
        fixed: 'right'
    },
]

const tableColumns3: any = [
    {
        title: "生产序号",
        key: "serialNum",
        dataIndex: "serialNum",
        width: 150,
    },
    {
        title: "织造单号",
        key: "weaveingCode",
        dataIndex: "weaveingCode",
        width: 150,
    },
    {
        title: "调机类型",
        key: "maintainType",
        dataIndex: "maintainType",
        width: 150,
    },
    {
        title: "机台号",
        key: "machineCode",
        dataIndex: "machineCode",
        width: 150,
    },
    {
        title: "位置号",
        key: "storey",
        dataIndex: "storey",
        width: 150,
    },
    {
        title: "计划单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 200,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    {
        title: "产品类别",
        key: "productType",
        dataIndex: "productType",
        width: 150,
    },
    {
        title: "分配重量",
        key: "alreadyWeight",
        dataIndex: "alreadyWeight",
        slotName: "alreadyWeight",
        width: 150,
    },
    {
        title: "分配匹数",
        key: "pieceNum",
        dataIndex: "pieceNum",
        width: 150,
    },
    {
        title: "上线时间",
        key: "startTime",
        dataIndex: "startTime",
        width: 180,
    },
    {
        title: "完成时间",
        key: "endTime",
        dataIndex: "endTime",
        width: 180,
    },
    {
        title: "针筒",
        key: "workDrum",
        dataIndex: "workDrum",
        width: 150,
    },
    {
        title: "订单交期",
        key: "weavDeliveryDate",
        dataIndex: "weavDeliveryDate",
        width: 150,
    },
    {
        title: "生产状态",
        key: "pStart",
        dataIndex: "pStart",
        slotName: 'pStart',
        width: 100,
        fixed: 'right'
    },
    {
        title: "状态",
        key: "rowsState",
        dataIndex: "rowsState",
        slotName: 'rowsState',
        width: 100,
        fixed: 'right'
    },
]

interface isDatalist {
    id: any
    schedulCode: any
    computerTime: any
    applyMachine: any
    firm: any
    storey: any
    defaultNum: any
    planOrderId: any,
    planOrderCode: any
}

let dataListss = reactive<isDatalist>(
    {
        id: '',
        schedulCode: '',
        computerTime: '',
        applyMachine: '',
        firm: '',
        storey: '',
        defaultNum: '',
        planOrderId: null,
        planOrderCode: null
    }
)

let dataListsss = ref<any[]>([])
const table = useTable()
const pageData = reactive({
    showAdd: false,
    rHeight: 0,
    clothListr: [],
    pageLoading: false
})
function lc() {
    post({
        url: "/planSingle/planSchedul/getMachineAreaPara",
        data: {
            firm: ""
        },
    }).then((res: any) => {
        if (res.code == 200) {

            pageData.clothListr = res.data
        }
    })
}
const storeyStor = (val: any) => {

    const resDtas = table.dataList.filter(item => {
        return item.id == gridOption.value.getSelectedRows()[0].id
    })
    post({
        url: "planSingle/planSchedulDetail/getList",
        data: {
            id: resDtas[0].id,
            firm: resDtas[0].firm,
            planOrderId: resDtas[0].planOrderId,
            planOrderCode: resDtas[0].planOrderCode,
            applyMachine: resDtas[0].applyMachine,
            storey: queryData.storey
        },
    }).then((res: any) => {
        if (res.code == 200) {
            macNum.value = res.data.machineNum
            dataListssz.value = [res.data.planSchedulDetails[0]]
            dataListsss.value = res.data.planSchedulLooms
            post({
                url: "planSingle/planSchedulDetail/getMachine",
                data: {
                    id: resDtas[0].id,
                    firm: resDtas[0].firm,
                    planOrderId: resDtas[0].planOrderId,
                    planOrderCode: resDtas[0].planOrderCode,
                    applyMachine: resDtas[0].applyMachine,
                    storey: queryData.storey
                },
            }).then((res: any) => {
                if (res.code == 200) {
                    res.data.forEach((item: any) => {
                        item.startDate = [item.startDate, item.endDate]
                    })
                    dataListsss.value.unshift(...res.data)
                    if (res.data.length != 0) {
                        res.data.forEach((item: any) => {
                            changeIds.value.unshift(item.machineId)
                        })
                    }
                }
            })
        }
    })
}
let yupaicId: any;
const editHandler = (record: any) => {
    selectedRowKeys.value = [record.id]
    isYupai.value = '修改预排产'
    dataListss.schedulCode = record.schedulCode
    dataListss.computerTime = record.computerTime
    dataListss.applyMachine = record.applyMachine
    dataListss.firm = record.firm
    queryData.storey = record.storey
    dataListss.defaultNum = record.defaultNum
    dataListss.planOrderId = record.planOrderId
    dataListss.planOrderCode = record.planOrderCode
    // isDeFou(record.firm, record.planOrderId, record.id, record.planOrderCode, record.applyMachine, record.storey)
    post({
        url: "planSingle/planSchedulDetail/getList",
        data: {
            id: Number(record.id),
            firm: record.firm,
            planOrderId: record.planOrderId,
            planOrderCode: record.planOrderCode,
            applyMachine: record.applyMachine,
            storey: record.storey,
        },
    }).then((res: any) => {
        if (res.code == 200) {
            macNum.value = res.data.machineNum
            dataListssz.value = [res.data.planSchedulDetails[0]]
            // dataListsss.value = res.data.schedulPlanSchedulLooms
            dataListsss.value = res.data.planSchedulLooms
            // console.log(res.data.schedulPlanSchedulLooms)
            // if (res.data.schedulPlanSchedulLooms.length != 0) {
            //     res.data.schedulPlanSchedulLooms.forEach((item: any) => {
            //         changeIds.value.unshift(item.id)
            //         console.log(item)
            //     })
            // }
            // console.log(changeIds.value)
            post({
                url: "planSingle/planSchedulDetail/getMachine",
                data: {
                    id: Number(record.id),
                    firm: record.firm,
                    planOrderId: record.planOrderId,
                    planOrderCode: record.planOrderCode,
                    applyMachine: record.applyMachine,
                    storey: record.storey,
                },
            }).then((res: any) => {
                if (res.code == 200) {
                    res.data.forEach((item: any) => {
                        item.startDate = [item.startDate, item.endDate]
                    })
                    dataListsss.value.unshift(...res.data)
                    if (res.data.length != 0) {
                        res.data.forEach((item: any) => {
                            changeIds.value.unshift(item.machineId)
                        })
                    }
                    pageData.showAdd = true
                }
            })
        }
    })

    yupaicId = record.id
}

let isYupai = ref()
let isS: any;

let dataListssz: any = ref([])
// function isDeFou(firm: any, planOrderId: any, id: any, planOrderCode: any, applyMachine: any, storey: any) {
//     post({
//         url: "planSingle/planSchedulDetail/getList",
//         data: {
//             id,
//             firm,
//             planOrderId,
//             planOrderCode,
//             applyMachine,
//             storey,
//         },
//     }).then((res: any) => {
//         if (res.code === 200) {
//             dataListssz.value = [res.data.planSchedulDetails[0]]
//             dataListsss.value = res.data.planSchedulLooms
//             if (res.data.schedulPlanSchedulLooms.length != 0) {
//                 res.data.schedulPlanSchedulLooms.forEach((item: any) => {
//                     dataListsss.value.unshift({
//                         id: item.id,
//                         firm: item.firm,
//                         machineCode: item.machineCode,
//                         startDate: [item.startDate, item.endDate]
//                     })
//                     changeIds.value.unshift(item.id)
//                 })
//             }
//         } else {
//             Message.error(res.message)
//         }
//     })
// }

let changeIdArry: any[] = []
let changeIds = ref<any[]>([])
const changeId = (value: any) => {
    changeIds.value = value
    const taData = table.dataList.filter((item: any) => {
        return gridOption.value.getSelectedRows()[0].id == item.id
    })
    let isDataList: any = []
    value.forEach((is: any) => {
        dataListsss.value.forEach((item: any) => {
            if (is == item.machineId) {
                isDataList.push({
                    createName: item.createName,
                    createTime: item.createTime,
                    deleteState: item.deleteState,
                    endDate: item.startDate[1],
                    firm: item.firm,
                    id: item.id,
                    machineCode: item.machineCode,
                    machineId: item.machineId,
                    machineName: item.machineName,
                    obsoleteState: item.obsoleteState,
                    planOrderCode: item.planOrderCode,
                    planSchedulId: item.planSchedulId,
                    remark: item.remark,
                    startDate: item.startDate[0],
                    storey: item.storey
                })
            }
        })
    })
    post(
        {
            url: 'planSingle/planSchedulDetail/schedulMachine',
            data: {
                ...taData[0],
                machine: isDataList
            }
        }
    ).then((res: any) => {
        if (res.code == 200) {
            post({
                url: "planSingle/planSchedulDetail/getList",
                data: {
                    id: gridOption.value.getSelectedRows()[0].id,
                    firm: taData[0].firm,
                    planOrderId: taData[0].planOrderId,
                    planOrderCode: taData[0].planOrderCode,
                    applyMachine: taData[0].applyMachine,
                    storey: queryData.storey
                },
            }).then((res: any) => {
                if (res.code == 200) {
                    macNum.value = res.data.machineNum
                    dataListssz.value = [res.data.planSchedulDetails[0]]
                    dataListsss.value = res.data.planSchedulLooms
                    post({
                        url: "planSingle/planSchedulDetail/getMachine",
                        data: {
                            id: gridOption.value.getSelectedRows()[0].id,
                            firm: taData[0].firm,
                            planOrderId: taData[0].planOrderId,
                            planOrderCode: taData[0].planOrderCode,
                            applyMachine: taData[0].applyMachine,
                            storey: queryData.storey
                        },
                    }).then((res: any) => {
                        if (res.code == 200) {
                            res.data.forEach((item: any) => {
                                item.startDate = [item.startDate, item.endDate]
                            })
                            dataListsss.value.unshift(...res.data)
                            // if (res.data.length != 0) {
                            //     res.data.forEach((item: any) => {
                            //         changeIds.value.unshift(item.machineId)
                            //     })
                            // }
                        }
                    })
                }
            })
        } else {
            changeIds.value = []
            Message.error(res.message)
        }
    })

}

const sendOemOrder = () => {
    let ptDatas = gridOption.value.getSelectedRows();
    console.log(ptDatas[0]);
    let greyCodeList = ptDatas.map((o) => { return o.greyCode; })
    let greyCodeSet = new Set(greyCodeList);
    if (greyCodeList.length == 0) {
        Message.error('请选择数据！')
        return
    }
    if (greyCodeSet.size > 1) {
        Message.error('请选择相同的坯布编号')
        return
    }

    post({
        url: '/planSingle/oemOrder/createOemOrder',
        data: ptDatas
    }).then(({ code, data }) => {
        console.log(code);
        if (code == 200) {
            Message.success('创建委外加工订单成功！')
            doRefresh();
        }
    })

}

const sideOk1 = () => {
    if (isYupai.value == '预排产') {
        let planOrderCodes: any;
        table.dataList.forEach((item: any) => {
            if (item.id == gridOption.value.getSelectedRows()[0].id) {
                planOrderCodes = item.planOrderCode
            }
        })
        let ischangeIdArrys: any = [];
        for (let i = 0; i < changeIds.value.length; i++) {
            dataListsss.value.forEach((item: any) => {
                if (item.machineId == changeIds.value[i]) {
                    ischangeIdArrys.push({
                        id: item.id,
                        firm: item.firm,
                        planOrderCode: planOrderCodes,
                        machineCode: item.machineCode,
                        startDate: item.startDate[0],
                        endDate: item.startDate[1],
                        storey: item.storey
                    })
                }
            })
        }
        if (ischangeIdArrys.length == 0) {
            Message.error('请选择机台')
            return
        }
        let planOrderCode;
        let customName;
        table.dataList.forEach((item: any) => {
            if (item.id == gridOption.value.getSelectedRows()[0].id) {
                planOrderCode = item.planOrderCode
                customName = item.customName
            }
        })
        let weaveCode;
        let greyCode;
        let greyName;
        dataListssz.value.forEach((item: any) => {
            weaveCode = item.weaveCode
            greyCode = item.greyCode
            greyName = item.greyName
        })
        post({
            url: 'planSingle/planSchedulDetail/temporarySave',
            data: {
                id: gridOption.value.getSelectedRows()[0].id,
                planOrderCode: planOrderCode,
                customName: customName,
                schedulCode: dataListss.schedulCode,
                computerTime: dataListss.computerTime,
                applyMachine: dataListss.applyMachine,
                storey: queryData.storey,
                defaultNum: dataListss.defaultNum,
                planSchedulLooms: ischangeIdArrys,
                weaveCode,
                greyCode,
                greyName,
                schedulState: 1
            }
        }).then((res: any) => {
            if (res.code == 200) {
                doRefresh()
                clearInterval(isS)
                post({
                    url: 'planSingle/planSchedul/upRedis'
                })
                pageData.showAdd = false
                selectedRowKeys.value = []
                changeIds.value = []
                dataListsss.value = []
                Message.success('保存成功')
            } else {
                Message.error(res.message)
            }
        })
    } else if (isYupai.value == '修改预排产') {
        let planOrderCodes: any;
        let customNames;
        table.dataList.forEach((item: any) => {
            if (item.id == yupaicId) {
                planOrderCodes = item.planOrderCode
                customNames = item.customName
            }
        })
        let ischangeIdArrys: any = [];
        for (let i = 0; i < changeIds.value.length; i++) {
            dataListsss.value.forEach((item: any) => {
                if (item.machineId == changeIds.value[i]) {
                    ischangeIdArrys.push({
                        id: item.id,
                        firm: item.firm,
                        planOrderCode: planOrderCodes,
                        machineCode: item.machineCode,
                        startDate: item.startDate[0],
                        endDate: item.startDate[1],
                        storey: item.storey
                    })
                }
            })
        }
        let weaveCode;
        let greyCode;
        let greyName;
        dataListssz.value.forEach((item: any) => {
            weaveCode = item.weaveCode
            greyCode = item.greyCode
            greyName = item.greyName
        })
        post({
            url: 'planSingle/planSchedulDetail/update',
            data: {
                id: Number(yupaicId),
                planOrderCode: planOrderCodes,
                customName: customNames,
                schedulCode: dataListss.schedulCode,
                computerTime: dataListss.computerTime,
                applyMachine: dataListss.applyMachine,
                storey: queryData.storey,
                defaultNum: dataListss.defaultNum,
                planSchedulLooms: ischangeIdArrys,
                weaveCode,
                greyCode,
                greyName,
            }
        }).then((res: any) => {
            if (res.code == 200) {
                doRefresh()
                clearInterval(isS)
                post({
                    url: 'planSingle/planSchedul/upRedis'
                })
                pageData.showAdd = false
                Message.success('保存成功')
                selectedRowKeys.value = []
                changeIds.value = []
                dataListsss.value = []
            } else {
                Message.error(res.message)
            }
        })
    } else if (isYupai.value == '排产') {
        let planOrderId: any
        let planOrderCodes: any
        let customNames: any
        let drawnNeedleState: any
        table.dataList.forEach((item: any) => {
            if (item.id == gridOption.value.getSelectedRows()[0].id) {
                planOrderId = item.planOrderId
                customNames = item.customName,
                    drawnNeedleState = item.drawnNeedleState
                planOrderCodes = item.planOrderCode
            }
        })
        let weaveCode: any;
        let greyCode: any;
        let greyName: any;
        dataListssz.value.forEach((item: any) => {
            weaveCode = item.weaveCode
            greyCode = item.greyCode
            greyName = item.greyName
        })
        let ischangeIdArrys: any = [];
        for (let i = 0; i < changeIds.value.length; i++) {
            dataListsss.value.forEach((item: any) => {
                if (item.machineId == changeIds.value[i]) {
                    ischangeIdArrys.push({
                        id: item.id,
                        planOrderCode: planOrderCodes,
                        machineCode: item.machineCode,
                        startDate: item.startDate[0],
                        endDate: item.startDate[1],
                        weaveCode,
                        greyCode,
                        greyName,
                        customName: customNames,
                        drawnNeedleState: drawnNeedleState,
                        storey: item.storey
                    })
                }
            })
        }
        post({
            url: 'planSingle/planSchedulDetail/save',
            data: {
                id: gridOption.value.getSelectedRows()[0].id,
                planOrderId,
                planOrderCode: planOrderCodes,
                planSchedulLooms: ischangeIdArrys,
                schedulCode: dataListss.schedulCode,
                weaveCode,
                greyCode,
                greyName,
                storey: queryData.storey,
                schedulState: 2
            }
        }).then((res: any) => {
            if (res.code == 200) {
                pageData.showAdd = false
                doRefresh()
                clearInterval(isS)
                post({
                    url: 'planSingle/planSchedul/upRedis'
                })
                changeIds.value = []
                Message.success('订单排产')
                selectedRowKeys.value = []
            } else {
                Message.error(res.message)
            }
        })
    }
}

const sidesOks = () => {
    if (ssmxBiao.value.length === 0) {
        Message.warning('请先试算')
    } else {
        post({
            url: '/planSingle/planSchedul/getScheduleSave',
            data: {
                ...dataListssz.value[0],
                ...dataListss,
                after: jtewmxBiao.value,
                save: ssmxBiao.value
            }
        }).then((res: any) => {
            if (res.code == 200) {
                Message.success('订单排产')
                clearInterval(isS)
                post({
                    url: 'planSingle/planSchedul/upRedis'
                })
                machinesIdArray.value = []
                machineIDs.value = []
                machineS.value = []
                machineS2.value = []
                changeIds.value = []
                changeIdArry = []
                selectedRowKeys.value = []
                pageData.showAdd = false
                jtdtBiao.value = []
                jtewmxBiao.value = []
                ssmxBiao.value = []
                ssmxBiao2.value = []
                selectedKeys2.value = []
                objArray.value = []
                emitter.emit('bcCx')
                doRefresh()
                // router.replace({ path: '/redirect/processrowfactory/planplant' })
            } else {
                Message.error(res.message)
            }
        })
    }
}

const sideNo1 = () => {
    // if (changeIds.value.length != 0 && isYupai.value == '预排产') {
    //     Message.error('请先取消勾选的机器')
    //     return
    // }
    clearInterval(isS)
    post({
        url: 'planSingle/planSchedul/upRedis'
    })
    machinesIdArray.value = []
    machineIDs.value = []
    machineS.value = []
    machineS2.value = []
    changeIds.value = []
    changeIdArry = []
    selectedRowKeys.value = []
    pageData.showAdd = false
    jtdtBiao.value = []
    jtewmxBiao.value = []
    ssmxBiao.value = []
    selectedKeys2.value = []
    objArray.value = []
}
const visible = ref(false)
const data: any = ref([])
const paichanxq = () => {
    if (changeIds.value.length == 0) {
        Message.error('请先选择机台')
        return
    }
    let jitaiArray: any = []
    let planOrderCode;
    table.dataList.forEach((item: any) => {
        if (item.id == gridOption.value.getSelectedRows()[0].id) {
            planOrderCode = item.planOrderCode
        }
    })
    changeIds.value.forEach((item: any) => {
        dataListsss.value.forEach((items: any) => {
            if (item == items.machineId) {
                // planOrderCode = items.planOrderCode
                jitaiArray.push(
                    {
                        machineCode: items.machineCode,
                        startDate: items.startDate[0],
                        endDate: items.startDate[1]
                    }
                )
            }
        })
    })
    post({
        url: 'planSingle/machineSchedul/getData',
        data: {
            planOrderCode,
            machines: jitaiArray
        }
    }).then((res: any) => {
        if (res.code == 200) {
            for (let i = 0; i < res.data.days.length; i++) {
                // columns.value.splice(columns.value.length - 1, 0, {
                //     title: res.data.days[i],
                //     key: res.data.days[i],
                //     dataIndex: res.data.days[i],
                //     slotName: res.data.days[i],
                //     width: 150
                // })
                columns.value.push({
                    title: res.data.days[i],
                    key: res.data.days[i],
                    dataIndex: res.data.days[i],
                    slotName: res.data.days[i],
                    width: 200
                })
            }
            data.value = res.data.machineSchedul
            maxData.value = res.data.maxData
            orderWeight.value = res.data.orderWeight
            visible.value = true
        } else {
            Message.error(res.message)
        }
    })
    // visible.value = true
}
const maxData: any = ref()
const orderWeight: any = ref()
const handleOk = async () => {
    // selectedRowKeys
    let jihudanhao: any;
    let pibubianhao: any;
    let pibuName: any;
    table.dataList.forEach((item: any) => {
        if (gridOption.value.getSelectedRows()[0].id == item.id) {
            jihudanhao = item.planOrderCode
            pibubianhao = item.greyCode
            pibuName = item.greyName
        }
    })
    let datas: any = []
    data.value.forEach((item: any) => {
        datas.push({
            ...item,
            planOrderCode: jihudanhao,
            greyCode: pibubianhao,
            greyName: pibuName
        })
    })
    const res: any = await post({
        url: 'planSingle/machineSchedul/insert',
        data: datas
    })
    if (res.code == 200) {
        Message.success(res.message)
        visible.value = false
        columns.value = [
            {
                title: "机台号",
                key: "machineCode",
                dataIndex: "machineCode",
                width: 150,
                fixed: 'left'
            },
            {
                title: "理论产量",
                key: "machineTargetCapacity",
                dataIndex: "machineTargetCapacity",
                width: 150,
                fixed: 'left'
            },
            {
                title: "极限日产能",
                key: "maxMachineTargetCapacity",
                dataIndex: "maxMachineTargetCapacity",
                width: 150,
                fixed: 'left'
            },
            // {
            //     title: "操作",
            //     key: "id",
            //     dataIndex: "id",
            //     slotName: "act4",
            //     width: 100,
            //     fixed: 'right'
            // },
        ]
        return true
    } else {
        Message.error(res.message)
        return false
    }
}
const handleCancel = () => {
    columns.value = [
        {
            title: "机台号",
            key: "machineCode",
            dataIndex: "machineCode",
            width: 150,
            fixed: 'left'
        },
        {
            title: "理论产量",
            key: "machineTargetCapacity",
            dataIndex: "machineTargetCapacity",
            width: 150,
            fixed: 'left'
        },
        {
            title: "极限日产能",
            key: "maxMachineTargetCapacity",
            dataIndex: "maxMachineTargetCapacity",
            width: 150,
            fixed: 'left'
        },
        // {
        //     title: "操作",
        //     key: "id",
        //     dataIndex: "id",
        //     slotName: "act4",
        //     width: 100,
        //     fixed: 'right'
        // },
    ]
    visible.value = false
}
const columns: any = ref([
    {
        title: "机台号",
        key: "machineCode",
        dataIndex: "machineCode",
        width: 150,
        fixed: 'left'
    },
    {
        title: "理论产量",
        key: "machineTargetCapacity",
        dataIndex: "machineTargetCapacity",
        width: 150,
        fixed: 'left'
    },
    {
        title: "极限日产能",
        key: "maxMachineTargetCapacity",
        dataIndex: "maxMachineTargetCapacity",
        width: 150,
        fixed: 'left'
    },
    // {
    //     title: "操作",
    //     key: "id",
    //     dataIndex: "id",
    //     slotName: "act4",
    //     width: 100,
    //     fixed: 'right'
    // },
])
let tc: any[] = tableColumns.map((o: any) => {

    let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed']
    }
    if (o.key === 'planOrderState') {
        obj['resizable'] = false
        obj['sortable'] = false
        obj["lockPosition"] = "right"
        obj['width'] = 206
        obj['cellRenderer'] = {
            template: ` <a-dropdown   @select="c($event)">
                <a-button @click="a" v-if="b== 2" type="primary" size="mini"
                    status="danger" shape="round">
                    紧急&nbsp
                    <icon-down />
                </a-button>
                <a-button @click="a" v-if="b == 0" type="primary" size="mini"
                    status="success" shape="round">
                    正常&nbsp
                    <icon-down />
                </a-button>
                <a-button @click="a" v-if="b == 1" status="danger" size="mini"
                    shape="round">
                    &nbsp&nbsp急&nbsp&nbsp
                    <icon-down />
                </a-button>
                <template #content>
                    <a-doption>紧急</a-doption>
                    <a-doption>急</a-doption>
                    <a-doption>正常</a-doption>
                </template >
               
            </a-dropdown>`,
            setup(props: any) {
                const a = () => {
                    handleSelects(props.params.data)
                }
                const c = ($event: any) => {
                    handleSelect($event)
                }
                return {
                    b: props.params.data.planOrderState,
                    a,
                    c,
                    d: props.params.data,
                    e: props.params.data.planState
                }
            }

        }
        obj['filterParams'] = {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '正常'
          : params.value == '1'
          ? '急'
          : params.value == '2'
          ? '紧急'
          : ''
      },
    }
        
    }
    if (o.key == "planState") {
        obj['resizable'] = false
        obj['sortable'] = false
        obj['cellRenderer'] = {
            template: ` <span v-if="b == 0">自行生产</span>`,
            setup(props: any) {
                return {
                    b: props.params.data.planState,

                }
            }
        }
        obj['filterParams'] = {
      valueFormatter: function (params: any) {
        return params.value == '0'
          ? '自行生产'
          : ''
      },
    }

    }

    return obj
})

let a = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    }]
tc = a.concat(tc)

let tc2: any[] = tableColumns2.map((o: any) => {

    let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed']
    }
    if (o.key == "pStart") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 100
        obj['cellRenderer'] = {
            template: ` <span>{{ b == 0 ? '等待' : '生产' }}</span>`,
            setup(props: any) {
                return {
                    b: props.params.data.pStart,

                }
            }
        }

    }

    return obj
})

let a2 = [{
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
}]
tc2 = a2.concat(tc2)

let tc3: any[] = tableColumns4.map((o: any) => {

    let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed']
    }
    if (o.key == "pStart") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 100
        obj['cellRenderer'] = {
            template: ` <span>{{ b == 0 ? '等待' : '生产' }}</span>`,
            setup(props: any) {
                return {
                    b: props.params.data.pStart,

                }
            }
        }

    }

    return obj
})

const ssListArray: any = ref([])

let tc4: any[] = tableColumns3.map((o: any) => {

    let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed']
    }
    if (o.key == "pStart") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 100
        obj['cellRenderer'] = {
            template: ` <span>{{ b == 0 ? '等待' : '生产' }}</span>`,
            setup(props: any) {
                return {
                    b: props.params.data.pStart,

                }
            }
        }

    }

    if (o.key == "rowsState") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 120
        obj['cellRenderer'] = {
            template: `<a-button size="mini" v-if="b == 0" type="outline">正常</a-button>
                   <a-button size="mini" v-if="b == 1" type="primary" status="danger">超出交期</a-button>`,
            setup(props: any) {
                return {
                    b: props.params.data.rowsState,

                }
            }
        }
    }

    if (o.key == "alreadyWeight") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 120
        // obj['editable'] = true
        // obj['valueParser'] = (params: any) => {
        //     ssListArray.value.push(params.data)
        //     return Number(params.newValue)
        // }
        obj['cellRenderer'] = {
            template: `<a-input-number v-model="b.alreadyWeight"></a-input-number>`,
            setup(props: any) {
                return {
                    b: ref(props.params.data),

                }
            }
        }
    }

    return obj
})

let tc5: any[] = tableColumns1.map((o: any) => {

    let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed']
    }
    if (o.key == "pStart") {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['width'] = 100
        obj['cellRenderer'] = {
            template: ` <span>{{ b == 0 ? '等待' : '生产' }}</span>`,
            setup(props: any) {
                return {
                    b: props.params.data.pStart,

                }
            }
        }

    }

    return obj
})
const macNum: any = ref('')
const maxTimeDate = ref('')
const tiemsData = (maxTime: any) => {
    maxTimeDate.value = maxTime
    console.log(maxTimeDate.value)
}
const disbledDatas = (current: any) => {
    return dayjs(current).isBefore(dayjs(maxTimeDate.value))
}
const localeText1: any = ref(localeText)


const form: any = reactive({
    customName: '',
    planOrderCode: '',
    greyCode: ''
})


const defaultColDef: any = {
    sortable: true,
    resizable: true,
    filter: true,
    // flex: 1
}

const huiche = () => {
    doRefresh()
}

emitter.on('pcUpdate', async (e: any) => {
    const { code, data, message } = await post({
        url: 'planSingle/planMachineTask/getUpdateInfo',
        data: e
    })
    if (code == 200) {
        console.log(data);
        dataListss.schedulCode = e.schedulCode
        dataListss.applyMachine = e.applyMachine
        queryData.storey = e.storey
        pageData.showAdd = true
        isYupai.value = '修改排产'
    } else {
        Message.error(message)
    }
})
const clickRowSelectionA = () => {
    gridOption5.value.getSelectedRows()[0].id = gridOption5.value.getSelectedRows()[0].greyId
    emitter.emit('noPaiCanRowIdisXq', gridOption5.value.getSelectedRows()[0])
}
const { saveGridState: saveGridState01, updateGridState: updateGridState01 } = saveOrUpdateGridState01('NotScheduled-1', gridOption, colState, tc)
const onColumnMoved = () => {
    saveGridState01()
}
const onColumnResized = () => {
    saveGridState01()
}
const onColumnVisible = () => {
    saveGridState01()
}

const GTpc = ref(false)

const paichanxs = () => {
    GTpc.value = true
}



const ArrayList = ref()

const selectClickArrayList = () => {
    post({
        url: 'planSingle/machineLayout/getScheduleInfo'
    }).then(({ data, code }) => {
        if (code == 200) {
            ArrayList.value = data
            ArrayList.value.forEach((item) => {
                item.detail = JSON.parse(item.detail)
            })
            console.log(ArrayList.value)
        }
    })
}

const tabKey = ref(0)

const tabchange = (val) => {
    tabKey.value = val
}

const getColor = (text: any, type: any) => {
    let color = ''
    // console.log(type)
    if (text == '机台') {
        if (type == 0) color = 'rgb(99,222,235)'
        if (type == 1) color = '#5959f5'
        if (type == 2) color = '#4cc784'
        if (type == 3) color = 'rgb(239,118,118)'
        if (!type && type != 0) color = 'green'
    }
    if (text == '其他') color = '#c9bbbb'
    if (text == '通道') color = 'rgb(243,217,11)'
    return color
}

const getEdit = () => {

}

watch(() => machinesIdArray.value, () => {
    ArrayList.value.forEach((item: any) => {
        item.detail.layout.forEach((items: any) => {
            if (machinesIdArray.value.includes(items.id)) {
                items.isBooval = true
            } else {
                items.isBooval = false
            }
        })
    })
})

const visibleSelectAll: any = ref(false)

const selectClickAll = () => {
    visibleSelectAll.value = true
}
const ArrayListMacAll = ref([])

const selectMxAll = () => {
    post({
        url: 'planSingle/machineLayout/getStoryScheduleInfo',
        data: {
            planOrderCode: gridOption.value.getSelectedRows()[0].planOrderCode
        }
    }).then(({ data }) => {
        ArrayListMacAll.value = data
    })
}
</script>
<style lang='less' scoped>
.evenRowStyl {
    background-color: red !important;
}

.cssToolbar {
    margin-bottom: 10px;
    text-align: right;
}

.iscon {
    width: 100%;
    height: 100%;
    display: flex;
}

.iscontent {
    width: 65%;
    height: 100%;
}

.iscontent2 {
    width: 35%;
    height: 100%;

    .iscontent21 {
        padding: 20px;
        height: 100%;

        .divs {
            margin-top: 10px;
            height: 30%;
            border-bottom: 1px dashed #ccc;
        }

        .divs2 {
            position: relative;

            span {
                position: absolute;
                right: 50px;
                top: 30px;
            }
        }
    }
}

.bg-content {
    width: 100%;
    height: 10%;
    // zoom: 1;
    margin-bottom: 2px;

    :deep(.arco-checkbox-group) {

        // width: 100% !important;
        // border-top: 1px dashed #ccc !important;
        // justify-content: space-around !important;
        // display: flex !important;
        // flex-wrap: wrap !important;
        // text-align: center !important;
        // height: 200px;
        // overflow: scroll;
        .bg-contentA {
            width: 100%;
            border-top: 1px dashed #ccc !important;
            // justify-content: space-around !important;
            display: flex !important;
            align-items: center;
            // flex-wrap: wrap !important;
            text-align: center !important;
            height: 120px;
            margin-bottom: 2px;
            zoom: 1;
            // margin-left: 60px;
        }
    }

    div {
        margin-top: 10px;
        margin-left: 5px;
        text-align: left;

        div {
            width: 150px;
            height: 50px;
            text-align: center;
            border: 1px solid #ccc;
        }
    }
}

:deep(.arco-checkbox-label) {
    margin-top: 15px;
}

.huClass {
    background-color: #A4FFCB;
}

.lvClass {
    background-color: #FFFDBB;
}

.wxClass {
    background-color: red;
}

#aTag {
    height: 80px;
    width: 60px;
    text-align: center;
    position: sticky;
    left: 1px;
    z-index: 1888;
}

// ::v-deep .arco-drawer {
//     position: absolute;
//     display: flex;
//     flex-direction: column;
//     width: 100%;
//     height: 100%;
//     overflow: auto;
//     line-height: 1.5715;
//     background-color: var(--color-bg-3);
//     z-index: 9999;
// }
.jitaipaic {
    display: flex;

    .jitaipaic1 {
        margin-left: 50px;
    }
}

:deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.layoutBox {
    width: 100%;
    height: 100%;
    overflow: auto;
}

.layoutBoxs {
    width: 100%;
    height: 100%;
}

.grid_cals2 {
    width: 100%;
    overflow: auto;
    display: -webkit-box;
    -webkit-overflow-scrolling: touch;
    height: 75vh !important;
}

.grid-item {
    // border-top: 2px solid rgba(1, 153, 209, 0.5);
    border: #999 dashed 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
}

.clmodule {
    // display: flex;
    // justify-content: center;
    // align-items: center;
    // align-self: center;
    height: 100%;
    color: #000;
    font-weight: 600;
}

.arco-checkbox-group {
    display: inline !important;
}

.borderClass {
    border: 8px solid red;
}

:deep(.is-leaf) {
    background-color: #dde2eb !important;
    border-right: 1px solid #ccc !important;
}

:deep(.cell) {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}
</style>